package com.larsgard.gedviewer.server.storage;

import java.util.ArrayList;

public class GedFileStorage extends Storage<GedFile> {
    private static GedFileStorage INSTANCE;

    private GedFileStorage() {

    }

    public static GedFileStorage getInstance() {
	if (INSTANCE == null) {
	    INSTANCE = new GedFileStorage();

	}
	return INSTANCE;
    }

    public GedFile storeFile(GedFile toStore) {
	if (toStore.getKey() == null) {
	    toStore.setKey(createKey(toStore, toStore.getFileId(), null));
	}
	return super.storeObject(toStore);
    }

    public GedFile getFile(String fileId) {
	ArrayList<GedFile> list = super.getObjectList(GedFile.class, 0, 1, null, "fileId == '"
		+ fileId + "'");
	if (list.size() != 1) {
	    return null;
	}
	return list.get(0);
    }

    public void deleteFile(GedFile gedFile) {
	super.deleteObject(gedFile);

    }
}
